import React from 'react'
// 引入store子模块
import { CounterStore } from './counter.Store'
import { ListStore } from './list.Store'

// 声明根rootStore
class RootStore {
  constructor() {
    // 实例化子模块
    this.counterStore = new CounterStore()
    this.listStore = new ListStore()
  }
}

// 实例化
const rootStore = new RootStore()

// 使用react context机制，完成统一方法封装
const context = React.createContext(rootStore)

// 通过useContext拿到rootStore实例对象，然后返回
const useStore = () => React.useContext(context)

export { useStore }